﻿module Sustainalytics.Governance {

    import Common = Sustainalytics.Common;
    import Company = Sustainalytics.Company;
    import LRTM = Sustainalytics.LRTM;
    import Research = Sustainalytics.Research;
    import EsgUtility = Sustainalytics.EsgRatings.EsgUtility;

    export class SummaryRelativePerformanceDetailsController  {
        
        public companyRelativePerformanceDetails: GovernanceRelativePerformanceDetailsDto;
        private govProfile: GovernanceProfileController;
        public notFoundMessage: string;
        public $routeParams: any;
        public options: any;

        //private userId: string;
        //private accountId: string;

        constructor(
            private $rootScope: ng.IScope,
            protected $scope: Company.ICompanyBasedScope,
            protected $q: ng.IQService,
            protected $sce: ng.ISCEService,
            protected $timeout: ng.ITimeoutService,
            protected $location: ng.ILocationService,
            protected RoutingService: Routing.IRoutingService,
            protected CompanyService: Company.ICompanyService,
            protected GovernanceCompanyProfileService: GovernanceCompanyProfileService,
            protected LongRunningTaskManagerService: LRTM.LongRunningTaskManagerService) {

            this.govProfile = this.$scope['governancectrl'];
            var ctx = this;
            ctx.options = {
                floor: 0,
                ceil: 100,
                readOnly: true,
                hideLimitLabels: true
            }
            ctx.govProfile = this.$scope['governancectrl'];
            ctx.getOverallPerformance();
        }

        private getOverallPerformance(): ng.IPromise<GovernanceRelativePerformanceDetailsDto> {
            var ctx = this;

            var promise = ctx.GovernanceCompanyProfileService.getCompanyRelativePerformanceDetails(ctx.govProfile.company.id);
            ctx.$rootScope['loading'] = true;
            promise.then(function (res: any) {
                if (res.errCode != undefined) {
                    console.log(res.message);
                }
                else {
                    ctx.$timeout(function () {
                        ctx.$scope.$apply(function () {
                            ctx.companyRelativePerformanceDetails = res;
                            ctx.$rootScope['loading'] = false;
                        });
                    });
                }
            }).finally(() => {
                ctx.$rootScope['loading'] = false;
            });

            return promise;
        }

        public getAssesmentType(assesmentType:number): string {
            return EsgUtility.getEsgPositionName(assesmentType);
        }

        private switchView(selected: string): void {
            this.govProfile.selectedIssueAnchor = selected;
            this.govProfile.changeView(this.govProfile.getViewNames().Issues); 
        }
    }

    angular.module(governanceModuleName).controller('SummaryRelativePerformanceDetailsController', ['$rootScope', '$scope', '$q', '$sce', '$timeout', '$location', 'RoutingService', 'CompanyService', 'GovernanceCompanyProfileService', 'LongRunningTaskManagerService', SummaryRelativePerformanceDetailsController]);

}  